let dataSource = {
    "水库": new Cesium.CustomDataSource('水库'),
    "地质灾害隐患点": new Cesium.CustomDataSource('地质灾害隐患点'),
    "漫水桥(路)": new Cesium.CustomDataSource('漫水桥(路)'),
    "危房": new Cesium.CustomDataSource('危房'),
    "旅游景区景点": new Cesium.CustomDataSource('旅游景区景点'),
    "易淹易涝点(区)": new Cesium.CustomDataSource('易淹易涝点(区)'),
    "渔船": new Cesium.CustomDataSource('渔船'),
    "渔港": new Cesium.CustomDataSource('渔港'),
    "塔吊": new Cesium.CustomDataSource('塔吊'),
    "其他": new Cesium.CustomDataSource('其他'),
    "三防责任人信息": new Cesium.CustomDataSource('三防责任人信息'),
};
const image = {
    "水库": "./images/sjzx/icons/水库.png",
    "地质灾害隐患点": "./images/sjzx/icons/地质灾害隐患点.png",
    "漫水桥(路)": "./images/sjzx/icons/漫水桥(路).png",
    "危房": "./images/sjzx/icons/危房.png",
    "旅游景区景点": "./images/sjzx/icons/旅游景区景点.png",
    "易淹易涝点(区)": "./images/sjzx/icons/易淹易涝点(区).png",
    "渔船": "./images/sjzx/icons/渔船.png",
    "渔港": "./images/sjzx/icons/渔港.png",
    "塔吊": "./images/sjzx/icons/塔吊.png",
    "其他": "./images/sjzx/icons/其他.png",
    "三防责任人信息": "./images/sjzx/icons/三防责任人信息.png",
    "高危存储企业": "./images/sjzx/icons/高危存储企业.png",
    "实时渔船": "./images/sjzx/icons/实时渔船.png",
    "在建工地": "./images/sjzx/icons/在建工地.png",
    "非煤矿山安全生产": "./images/sjzx/icons/非煤矿山安全生产.png",
    "企业信息": "./images/sjzx/icons/企业信息.png",
    "重大危险源信息": "./images/sjzx/icons/重大危险源信息.png",
    "消防队伍": "./images/sjzx/icons/消防队伍.png",
    "扑火队伍": "./images/sjzx/icons/扑火队伍.png",
    "社会救援组织": "./images/sjzx/icons/专家.png",
    "自然灾害类专家": "./images/sjzx/icons/专家.png",
    "事故灾难类专家": "./images/sjzx/icons/专家.png",
    "综合资讯类": "./images/sjzx/icons/专家.png",
    "公共卫生社会安全类": "./images/sjzx/icons/专家.png",
    "防汛物资仓库": "./images/sjzx/icons/防汛物资仓库.png",
    "救灾物资仓库": "./images/sjzx/icons/救灾物资仓库.png",
    "医院": "./images/sjzx/icons/医院.png",
    "卫生院": "./images/sjzx/icons/卫生院.png",
    "诊所": "./images/sjzx/icons/诊所.png",
    "急救中心": "./images/sjzx/icons/急救中心.png",
    "其他医疗机构": "./images/sjzx/icons/其他医疗机构.png",
    "台风避难场所": "./images/sjzx/icons/台风避难场所.png",
    "洪涝避难场所": "./images/sjzx/icons/洪涝避难场所.png",
    "地震避难场所": "./images/sjzx/icons/地震避难场所.png",
    "防洪楼": "./images/sjzx/icons/防洪楼.png",
    "避风港": "./images/sjzx/icons/避风港.png",
    "大学": "./images/sjzx/icons/大学.png",
    "高中": "./images/sjzx/icons/高中.png",
    "小学": "./images/sjzx/icons/小学.png",
    "幼儿园": "./images/sjzx/icons/幼儿园.png",
    "其他类型学校": "./images/sjzx/icons/其他类型学校.png",
    "初中": "./images/sjzx/icons/初中.png",
    "防火瞭望台": "./images/sjzx/icons/防火瞭望台.png",
    "地震及火山检测台": "./images/sjzx/icons/地震及火山检测台.png"
};
let constant = Math.PI / 180;
function addPoints(pointType, pointData, kbApiDetail, eventType, event) {
    let bw = 0;
    let bh = 0;
    if (screen.width < 2000) {
        bw = 40;
        bh = 40;
    } else if (screen.width > 3000) {
        bw = 60;
        bh = 60;
    }
    pointData.forEach(point => {
        let currentId = point.id ? (point.id + pointType) : (point.name + pointType)
        // 更新数据时使用
        let entity = viewer.entities.getById(currentId);
        if (entity) {
            return
            // entity.position = Cesium.Cartesian3.fromDegrees(Number(car.lon00306599), Number(car.lat00306598), 0);
        } else {
            let x = null;
            let y = null;
            if (point.sfkx == "是" || point.sfkx == undefined) {
                if (point.lon && point.lat) {
                    x = point.lon
                    y = point.lat
                } else if (point.lng && point.lat) {
                    x = point.lng
                    y = point.lat
                } else if (point.jd && point.wd) {
                    x = point.jd
                    y = point.wd
                }
                //console.log(labelDistance[point.distance][1], labelDistance[point.distance][0])
                let bill = viewer.entities.add({
                    id: point.id ? (point.id + pointType) : (point.name + pointType),//渔船没有id,其他都是id
                    detailId: point.id ? point.id : point.name,
                    position: Cesium.Cartesian3.fromDegrees(Number(x), Number(y), 0),
                    billboard: {
                        image: image[pointType], // default: undefined
                        horizontalOrigin: Cesium.HorizontalOrigin.CENTER, // default
                        verticalOrigin: Cesium.VerticalOrigin.BOTTOM, // default: CENTER
                        // color : Cesium.Color.LIME, // default: WHITE
                        width: bw,
                        height: bh,
                        heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                        scaleByDistance: new Cesium.NearFarScalar(80000, .7, 1000000, 0.5),
                        // distanceDisplayCondition: point.distance ? new Cesium.DistanceDisplayCondition(labelDistance[point.distance][1], labelDistance[point.distance][0]) : new Cesium.DistanceDisplayCondition(0)
                    },
                    type: pointType,//防汛防风类型
                    kbApiDetail,
                    // label: {
                    //     text: point.name ? point.name : point.charge,
                    //     show: true,
                    //     font: '15pt Source Han Sans CN', //字体样式
                    //     fillColor: Cesium.Color.LAWNGREEN, //字体颜色
                    //     outlineColor: Cesium.LabelStyle.BLACK,
                    //     style: Cesium.LabelStyle.FILL_AND_OUTLINE, //label样式
                    //     outlineWidth: 4,
                    //     // heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                    //     verticalOrigin: Cesium.VerticalOrigin.TOP, //垂直位置
                    //     horizontalOrigin: Cesium.HorizontalOrigin.CENTER, //水平位置
                    //     pixelOffset: new Cesium.Cartesian2(0, 0), //偏移
                    //     // distanceDisplayCondition: point.distance ? new Cesium.DistanceDisplayCondition(labelDistance[point.distance][1], labelDistance[point.distance][0]) : new Cesium.DistanceDisplayCondition(0, 6000),
                    // },
                });
                //添加点击事件
                if (eventType && event) {
                    bill[eventType] = event
                }
                entitiesArr.push(bill)
            } else {
                return
            }
        }
    });
}
function addNewPoints(pointType, pointData, kbApiDetail, eventType, event) {
    let bw = 0;
    let bh = 0;
    if (screen.width < 2000) {
        bw = 28;
        bh = 42;
    } else if (screen.width > 3000) {
        bw = 60;
        bh = 60;
    }
    pointData.forEach(point => {
        let currentId = point.id ? (point.id + pointType) : (point.name + pointType)
        // 更新数据时使用
        let entity = viewer.entities.getById(currentId);
        if (entity) {
            return
            // entity.position = Cesium.Cartesian3.fromDegrees(Number(car.lon00306599), Number(car.lat00306598), 0);
        } else {
            let x = null;
            let y = null;
            if (point.sfkx == "是" || point.sfkx == undefined) {
                if (point.lon && point.lat) {
                    x = point.lon
                    y = point.lat
                } else if (point.lng && point.lat) {
                    x = point.lng
                    y = point.lat
                } else if (point.jd && point.wd) {
                    x = point.jd
                    y = point.wd
                }
                //console.log(labelDistance[point.distance][1], labelDistance[point.distance][0])
                let bill = viewer.entities.add({
                    id: point.id ? (point.id + pointType) : (point.name + pointType),//渔船没有id,其他都是id
                    detailId: point.id ? point.id : point.name,
                    position: Cesium.Cartesian3.fromDegrees(Number(x), Number(y), 0),
                    billboard: {
                        image: image[pointType], // default: undefined
                        horizontalOrigin: Cesium.HorizontalOrigin.CENTER, // default
                        verticalOrigin: Cesium.VerticalOrigin.BOTTOM, // default: CENTER
                        // color : Cesium.Color.LIME, // default: WHITE
                        width: bw,
                        height: bh,
                        heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                        scaleByDistance: new Cesium.NearFarScalar(80000, .7, 1000000, 0.5),
                        // distanceDisplayCondition: point.distance ? new Cesium.DistanceDisplayCondition(labelDistance[point.distance][1], labelDistance[point.distance][0]) : new Cesium.DistanceDisplayCondition(0)
                    },
                    type: pointType,//防汛防风类型
                    kbApiDetail,
                    // label: {
                    //     text: point.name ? point.name : point.charge,
                    //     show: true,
                    //     font: '15pt Source Han Sans CN', //字体样式
                    //     fillColor: Cesium.Color.LAWNGREEN, //字体颜色
                    //     outlineColor: Cesium.LabelStyle.BLACK,
                    //     style: Cesium.LabelStyle.FILL_AND_OUTLINE, //label样式
                    //     outlineWidth: 4,
                    //     // heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                    //     verticalOrigin: Cesium.VerticalOrigin.TOP, //垂直位置
                    //     horizontalOrigin: Cesium.HorizontalOrigin.CENTER, //水平位置
                    //     pixelOffset: new Cesium.Cartesian2(0, 0), //偏移
                    //     // distanceDisplayCondition: point.distance ? new Cesium.DistanceDisplayCondition(labelDistance[point.distance][1], labelDistance[point.distance][0]) : new Cesium.DistanceDisplayCondition(0, 6000),
                    // },
                });
                //添加点击事件
                if (eventType && event) {
                    bill[eventType] = event
                }
                entitiesArr.push(bill)
            } else {
                return
            }
        }
    });
}
function addProductionPoints(pointType, pointData, kbApiDetail, eventType, event) {
    let bw = 0;
    let bh = 0;
    if (screen.width < 2000) {
        bw = 40;
        bh = 40;
    } else if (screen.width > 3000) {
        bw = 60;
        bh = 60;
    }
    pointData.forEach(point => {
        let currentId = point.id ? (point.id + pointType) : (point.name + pointType)
        // 更新数据时使用
        let entity = viewer.entities.getById(currentId);
        if (entity) {
            return
            // entity.position = Cesium.Cartesian3.fromDegrees(Number(car.lon00306599), Number(car.lat00306598), 0);
        } else {
            let x = null;
            let y = null;

            if (point.lon && point.lat) {
                x = point.lon
                y = point.lat
            } else if (point.lng && point.lat) {
                x = point.lng
                y = point.lat
            } else if (point.jd && point.wd) {
                x = point.jd
                y = point.wd
            }
            //1，市，2。县区，3，乡镇街道 3，村
            let labelDistance = {
                "1": [70000, 50000],
                "2": [50000, 30000],
                "3": [30000, 18000],
                "4": [18000, 0],
            }
            //console.log(labelDistance[point.distance][1], labelDistance[point.distance][0])
            let bill = viewer.entities.add({
                id: point.id ? (point.id + pointType) : (point.name + pointType),//渔船没有id,其他都是id
                detailId: point.id ? point.id : point.name,
                position: Cesium.Cartesian3.fromDegrees(Number(x), Number(y), 0),
                billboard: {
                    image: image[pointType], // default: undefined
                    horizontalOrigin: Cesium.HorizontalOrigin.CENTER, // default
                    verticalOrigin: Cesium.VerticalOrigin.BOTTOM, // default: CENTER
                    // color : Cesium.Color.LIME, // default: WHITE
                    width: bw,
                    height: bh,
                    heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                    scaleByDistance: new Cesium.NearFarScalar(80000, .7, 1000000, 0.5),
                    // distanceDisplayCondition: point.distance ? new Cesium.DistanceDisplayCondition(labelDistance[point.distance][1], labelDistance[point.distance][0]) : new Cesium.DistanceDisplayCondition(0)
                },
                type: pointType,//防汛防风类型
                kbApiDetail,
                // label: {
                //     text: point.name ? point.name : point.charge,
                //     show: true,
                //     font: '15pt Source Han Sans CN', //字体样式
                //     fillColor: Cesium.Color.LAWNGREEN, //字体颜色
                //     outlineColor: Cesium.LabelStyle.BLACK,
                //     style: Cesium.LabelStyle.FILL_AND_OUTLINE, //label样式
                //     outlineWidth: 4,
                //     // heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                //     verticalOrigin: Cesium.VerticalOrigin.TOP, //垂直位置
                //     horizontalOrigin: Cesium.HorizontalOrigin.CENTER, //水平位置
                //     pixelOffset: new Cesium.Cartesian2(0, 0), //偏移
                //     // distanceDisplayCondition: point.distance ? new Cesium.DistanceDisplayCondition(labelDistance[point.distance][1], labelDistance[point.distance][0]) : new Cesium.DistanceDisplayCondition(0, 6000),
                // },
            });
            //添加点击事件
            if (eventType && event) {
                bill[eventType] = event
            }
            entitiesArr.push(bill)
        }
    });
}
// 实时渔船
function addYC(pointType, pointData, kbApiDetail, eventType, event) {
    let bw = 0;
    let bh = 0;
    if (screen.width < 2000) {
        bw = 40;
        bh = 40;
    } else if (screen.width > 3000) {
        bw = 60;
        bh = 60;
    }
    console.log(pointData[0])
    pointData.forEach(point => {

        // 更新数据时使用
        let entity = viewer.entities.getById(point.terminalCode);
        if (entity) {
            entity.position = Cesium.Cartesian3.fromDegrees(Number(point.longitude), Number(point.latitude), 0);
            return
        } else {
            let bill = viewer.entities.add({
                id: point.terminalCode,
                position: Cesium.Cartesian3.fromDegrees(Number(point.longitude), Number(point.latitude), 0),
                billboard: {
                    image: image[pointType], // default: undefined
                    horizontalOrigin: Cesium.HorizontalOrigin.CENTER, // default
                    verticalOrigin: Cesium.VerticalOrigin.BOTTOM, // default: CENTER
                    // color : Cesium.Color.LIME, // default: WHITE
                    width: bw,
                    height: bh,
                    heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                    scaleByDistance: new Cesium.NearFarScalar(80000, .7, 1000000, 0.5),
                    // distanceDisplayCondition: point.distance ? new Cesium.DistanceDisplayCondition(labelDistance[point.distance][1], labelDistance[point.distance][0]) : new Cesium.DistanceDisplayCondition(0)
                },
                type: pointType,//防汛防风类型
            });
            //添加点击事件
            if (eventType && event) {
                bill[eventType] = event
            }
            entitiesArr.push(bill)
        }

    });
}
// 在建工地
function addGD(pointType, pointData, kbApiDetail, eventType, event) {
    let bw = 0;
    let bh = 0;
    if (screen.width < 2000) {
        bw = 40;
        bh = 40;
    } else if (screen.width > 3000) {
        bw = 60;
        bh = 60;
    }
    pointData.forEach(point => {
        // 更新数据时使用
        let entity = viewer.entities.getById(point.id);
        if (entity) {
            entity.position = Cesium.Cartesian3.fromDegrees(Number(point.lng), Number(point.lat), 0);
            return
        } else {
            let bill = viewer.entities.add({
                id: point.id,
                unitId: point.unitId,
                position: Cesium.Cartesian3.fromDegrees(Number(point.lng), Number(point.lat), 0),
                billboard: {
                    image: image[pointType], // default: undefined
                    horizontalOrigin: Cesium.HorizontalOrigin.CENTER, // default
                    verticalOrigin: Cesium.VerticalOrigin.BOTTOM, // default: CENTER
                    // color : Cesium.Color.LIME, // default: WHITE
                    width: bw,
                    height: bh,
                    heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                    scaleByDistance: new Cesium.NearFarScalar(80000, .7, 1000000, 0.5),
                    // distanceDisplayCondition: point.distance ? new Cesium.DistanceDisplayCondition(labelDistance[point.distance][1], labelDistance[point.distance][0]) : new Cesium.DistanceDisplayCondition(0)
                },
                type: pointType,//防汛防风类型
                entityDetail: point,
                kbApiDetail
            });
            //添加点击事件
            if (eventType && event) {
                bill[eventType] = event
            }
            entitiesArr.push(bill)
        }
    });
}
// 添加责任人
function addLabelPoints(pointType, pointData, kbApiDetail, eventType, event) {
    let labelDistance = {//476772,109580,109580
        "全市": [1000000, 283290],
        "全区": [283290, 109580],
        "全街道": [105580, 25088],

        "全镇": [100580, 25088],//117585
        "全县": [1000000, 109580],
        "全乡": [109580, 25088],
        "全村": [25088, 0]
    }
    pointData.forEach(point => {
        let x = null
        let y = null

        if (point.zxjd && point.zxwd) {
            x = Number(point.zxjd)
            y = Number(point.zxwd)
        }
        //1，市，2。县区，3，乡镇街道 3，村
        let lon = x / 180 * Math.PI;
        let lat = y / 180 * Math.PI;
        let near = labelDistance[point.distance][1];
        let far = labelDistance[point.distance][0];
        let position = Cesium.Cartesian3.fromDegrees(x, y);
        let bill = viewer.entities.add({
            detailId: point.id ? point.id : point.name,
            position: position,
            type: pointType,//防汛防风类型
            kbApiDetail,
            label: {
                text: `${point.address}(${point.count ? point.count : 1})\n责任人:${point.charge}`,
                show: new Cesium.CallbackProperty(() => {
                    let rectangle = viewer.camera.computeViewRectangle();
                    let distance = Cesium.Cartesian3.distance(viewer.camera.position, position);
                    if (near < distance
                        && distance < far
                        && rectangle.west < x * constant
                        && x * constant < rectangle.east
                        && rectangle.south < y * constant
                        && y * constant < rectangle.north) 
                    {
                        bill.label.show = true
                        return true
                    }
                    return false
                }, false),
                font: '12pt Source Han Sans CN', //字体样式
                fillColor: Cesium.Color.DARKORANGE, //字体颜色 LAWNGREEN
                outlineWidth: 4,
                outlineColor: Cesium.LabelStyle.BLACK,
                style: Cesium.LabelStyle.FILL_AND_OUTLINE, //label样式
                heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                verticalOrigin: Cesium.VerticalOrigin.TOP, //垂直位置
                horizontalOrigin: Cesium.HorizontalOrigin.CENTER, //水平位置
                // pixelOffset: new Cesium.Cartesian2(0, 0), //偏移
                distanceDisplayCondition: new Cesium.DistanceDisplayCondition(labelDistance[point.distance][1], labelDistance[point.distance][0])
            },
            labelDistance: point.distance,
            zxlon: point.zxjd,
            zxlat: point.zxwd,

        });
        //添加点击事件
        if (eventType && event) {
            bill[eventType] = event
        }
        entitiesArr.push(bill)
        // }
    });
}
function addLabels(pointType, pointData, kbApiDetail, eventType, event) {

    pointData.forEach(point => {
        // 更新数据时使用
        // let entity = entities.getById(car.vehicleno10000034);
        // if (entity) {
        //     entity.position = Cesium.Cartesian3.fromDegrees(Number(car.lon00306599), Number(car.lat00306598), 0);
        // } else {
        let x = null
        let y = null
        // if (point.lon && point.lat) {
        //     x = point.lon
        //     y = point.lat
        // } else if (point.lng && point.lat) {
        //     x = point.lng
        //     y = point.lat
        if (point.zxjd && point.zxwd) {
            x = point.zxjd
            y = point.zxwd
        }
        let fz = '';
        if (screen.width < 2000) {

            fz = '12pt Source Han Sans CN';
        } else if (screen.width > 3000) {

            fz = '20pt Source Han Sans CN';
        }
        //1，市，2。县区，3，乡镇街道 3，村
        let labelDistance = {//476772,109580,109580
            "全市": [1000000, 283290],
            "全县": [1000000, 109580],
            "全区": [283290, 109580],
            "全镇": [109580, 25088],//117585
            "全乡": [109580, 25088],
            "全村": [25088, 0]
        }
        let labelImg = {
            "全市": "./images/sjzx/icons/三防责任人信息.png",
            "全县": "./images/sjzx/icons/三防责任人信息.png",
            "全区": "./images/sjzx/icons/三防责任人信息.png",
            "全镇": "./images/sjzx/icons/三防责任人信息2.png",
            "全乡": "./images/sjzx/icons/三防责任人信息2.png",
            "全村": "./images/sjzx/icons/三防责任人信息1.png",
        }
        let count = point.count ? point.count : 1;
        let textContent = `${point.address}(${count})\n责任人:${point.charge}`;
        let obj = {
            textContent: textContent
        }
        let bill = layerManager.labels.add({
            //id: point.id ? (point.id+pointType) : (point.name+pointType),//渔船没有id,其他都是id
            // detailId: point.id ? point.id : point.name,
            position: Cesium.Cartesian3.fromDegrees(Number(x), Number(y), 0),
            // type: pointType,//防汛防风类型
            kbApiDetail,
            text: obj.textContent,// `${point.address}(${point.count ? point.count : 1})\n责任人:${point.charge}`,//,
            show: true,
            font: fz, //字体样式
            fillColor: Cesium.Color.DARKORANGE, //字体颜色 LAWNGREEN
            // backgroundColor: Cesium.Color.GREY, //背景颜色
            // showBackground: true, //是否显示背景颜色
            outlineWidth: 4,
            outlineColor: Cesium.LabelStyle.BLACK,
            style: Cesium.LabelStyle.FILL_AND_OUTLINE, //label样式
            heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
            verticalOrigin: Cesium.VerticalOrigin.TOP, //垂直位置
            horizontalOrigin: Cesium.HorizontalOrigin.CENTER, //水平位置
            pixelOffset: new Cesium.Cartesian2(0, 0), //偏移
            distanceDisplayCondition: new Cesium.DistanceDisplayCondition(labelDistance[point.distance][1], labelDistance[point.distance][0]),
            // labelDistance: point.distance,
            // zxlon: point.zxjd,
            // zxlat: point.zxwd,
        });
        //添加点击事件
        if (eventType && event) {
            bill[eventType] = event
        }
        // }
    });
}
function addLabels1(pointType, pointData, kbApiDetail, eventType, event) {

    pointData.forEach(point => {
        // 更新数据时使用
        // let entity = entities.getById(car.vehicleno10000034);
        // if (entity) {
        //     entity.position = Cesium.Cartesian3.fromDegrees(Number(car.lon00306599), Number(car.lat00306598), 0);
        // } else {
        let x = null
        let y = null
        // if (point.lon && point.lat) {
        //     x = point.lon
        //     y = point.lat
        // } else if (point.lng && point.lat) {
        //     x = point.lng
        //     y = point.lat
        if (point.zxjd && point.zxwd) {
            x = point.zxjd
            y = point.zxwd
        }
        let fz = '';
        if (screen.width < 2000) {

            fz = '12pt Source Han Sans CN';
        } else if (screen.width > 3000) {

            fz = '20pt Source Han Sans CN';
        }
        //1，市，2。县区，3，乡镇街道 3，村
        let labelDistance = {//476772,109580,109580
            "全市": [1000000, 283290],
            "全县": [1000000, 109580],
            "全区": [283290, 109580],
            "全镇": [109580, 25088],//117585
            "全乡": [109580, 25088],
            "全村": [25088, 0]
        }
        let labelImg = {
            "全市": "./images/sjzx/icons/三防责任人信息.png",
            "全县": "./images/sjzx/icons/三防责任人信息.png",
            "全区": "./images/sjzx/icons/三防责任人信息.png",
            "全镇": "./images/sjzx/icons/三防责任人信息2.png",
            "全乡": "./images/sjzx/icons/三防责任人信息2.png",
            "全村": "./images/sjzx/icons/三防责任人信息1.png",
        }
        let count = point.count ? point.count : 1;
        let textContent = `${point.address}(${count})\n责任人:${point.charge}`;
        let obj = {
            textContent: textContent
        }
        let bill = layerManager.labels1.add({
            //id: point.id ? (point.id+pointType) : (point.name+pointType),//渔船没有id,其他都是id
            // detailId: point.id ? point.id : point.name,
            position: Cesium.Cartesian3.fromDegrees(Number(x), Number(y), 0),
            // type: pointType,//防汛防风类型
            kbApiDetail,
            text: obj.textContent,// `${point.address}(${point.count ? point.count : 1})\n责任人:${point.charge}`,//,
            show: true,
            font: fz, //字体样式
            fillColor: Cesium.Color.DARKORANGE, //字体颜色 LAWNGREEN
            // backgroundColor: Cesium.Color.GREY, //背景颜色
            // showBackground: true, //是否显示背景颜色
            outlineWidth: 4,
            outlineColor: Cesium.LabelStyle.BLACK,
            style: Cesium.LabelStyle.FILL_AND_OUTLINE, //label样式
            heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
            verticalOrigin: Cesium.VerticalOrigin.TOP, //垂直位置
            horizontalOrigin: Cesium.HorizontalOrigin.CENTER, //水平位置
            pixelOffset: new Cesium.Cartesian2(0, 0), //偏移
            distanceDisplayCondition: new Cesium.DistanceDisplayCondition(labelDistance[point.distance][1], labelDistance[point.distance][0]),
            // labelDistance: point.distance,
            // zxlon: point.zxjd,
            // zxlat: point.zxwd,
        });
        //添加点击事件
        if (eventType && event) {
            bill[eventType] = event
        }
        // }
    });
}
function polymerization(data) {
    let polymericDataSource = new Cesium.CustomDataSource('StaticDataSource');
    let polymericDataSourceColl = polymericDataSource.entities;
    for (let i = 0; i < data.length; i++) {
        if (data[i].lat) {
            polymericDataSourceColl.add({
                position: Cesium.Cartesian3.fromDegrees(Number(data[i].lng), Number(data[i].lat), 0),
                label: {
                    text: `${data[i].address}(${data[i].count ? data[i].count : 1})\n责任人:${data[i].charge}`,
                    show: true
                }
            })
        }


    }
    var dataSourcePromise = viewer.dataSources.add(polymericDataSource);
    dataSourcePromise.then(function (dataSource) {
        var pixelRange = 15;
        var minimumClusterSize = 3;
        var enabled = true;
        dataSource.clustering.enabled = enabled;
        dataSource.clustering.pixelRange = pixelRange;
        dataSource.clustering.minimumClusterSize = minimumClusterSize;

        var removeListener;

        var pinBuilder = new Cesium.PinBuilder();
        // var pin50 = pinBuilder.fromText('50+', Cesium.Color.RED, 48).toDataURL();
        // var pin40 = pinBuilder.fromText('40+', Cesium.Color.ORANGE, 48).toDataURL();
        // var pin30 = pinBuilder.fromText('30+', Cesium.Color.YELLOW, 48).toDataURL();
        // var pin20 = pinBuilder.fromText('20+', Cesium.Color.GREEN, 48).toDataURL();
        // var pin10 = pinBuilder.fromText('10+', Cesium.Color.BLUE, 48).toDataURL();
        var singleDigitPins = new Array(8);
        for (var i = 0; i < singleDigitPins.length; ++i) {
            singleDigitPins[i] = pinBuilder.fromText('' + (i + 2), Cesium.Color.VIOLET, 48).toDataURL();
        }
        function customStyle() {
            if (Cesium.defined(removeListener)) {
                removeListener();
                removeListener = undefined;
            } else {
                removeListener = dataSource.clustering.clusterEvent.addEventListener(function (clusteredEntities, cluster) {
                    cluster.label.show = false;
                    cluster.billboard.show = true;
                    cluster.billboard.id = cluster.label.id;
                    cluster.billboard.verticalOrigin = Cesium.VerticalOrigin.BOTTOM;

                    if (clusteredEntities.length >= 1000) {
                        cluster.billboard.image = pinBuilder.fromText('' + clusteredEntities.length, Cesium.Color.RED, 48).toDataURL();//pin50;
                    } else if (clusteredEntities.length >= 500) {
                        cluster.billboard.image = pinBuilder.fromText('' + clusteredEntities.length, Cesium.Color.ORANGE, 48).toDataURL();//pin40;
                    } else if (clusteredEntities.length >= 300) {
                        cluster.billboard.image = pinBuilder.fromText('' + clusteredEntities.length, Cesium.Color.YELLOW, 48).toDataURL();
                    } else if (clusteredEntities.length >= 150) {
                        cluster.billboard.image = pinBuilder.fromText('' + clusteredEntities.length, Cesium.Color.GREEN, 48).toDataURL();
                    } else if (clusteredEntities.length >= 10) {
                        cluster.billboard.image = pinBuilder.fromText('' + clusteredEntities.length, Cesium.Color.BLUE, 48).toDataURL();
                    } else {
                        cluster.billboard.image = singleDigitPins[clusteredEntities.length - 2];
                    }
                });
            }
            var pixelRange = dataSource.clustering.pixelRange;
            dataSource.clustering.pixelRange = 0;
            dataSource.clustering.pixelRange = pixelRange;
        }
        customStyle();
        function subscribeParameter(name) {
            Cesium.knockout.getObservable(viewModel, name).subscribe(
                function (newValue) {
                    dataSource.clustering[name] = newValue;
                }
            );
        }
        subscribeParameter('pixelRange');
        subscribeParameter('minimumClusterSize');
    })

    // var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    // handler.setInputAction(function(movement) {
    //     var pickedLabel = viewer.scene.pick(movement.position);
    // }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
}
function polymerizationRemove() {
    if (comjs.polymericDataSource) {
        comjs.polymericDataSource.removeAll()
        comjs.polymericDataSource = null;
    }
}
function removePointBySign(typeName) {

    for (var i = 0; i < entitiesArr.length; i++) {

        if (entitiesArr[i].type === typeName) {
            viewer.entities.remove(entitiesArr[i]);

            entitiesArr.splice(i, 1);
            i--;
        }
    }
}
function removeLabels() {
    layerManager.labels.removeAll()
}
function removeAll() {
    for (var i = 0; i < entitiesArr.length; i++) {
        viewer.entities.remove(entitiesArr[i]);
        entitiesArr.splice(i, 1);
        i--;
    }
}
function changeLabelShow(typeName, status) {
    for (var i = 0; i < entitiesArr.length; i++) {
        if (entitiesArr[i].type === typeName) {
            entitiesArr[i].show = status
            console.log(entitiesArr[i].show)
        }
    }
}
export default {
    addPoints,
    removePointBySign,
    removeAll,
    addLabelPoints,
    addLabels,
    removeLabels,
    changeLabelShow,
    addProductionPoints,
    addYC,
    addGD,
    addNewPoints,
    polymerization,
    addLabels1
};
